﻿/*
*   学员端课程收藏列表页面
*/
// 主页内容 由于angular 独立域（又懒加载）所以这里不能再用 jisuStuApp 了 只能angular.module('jisuStuHome') 获取模块后加controller 这样才能懒加载成功
angular.module('jisuStuHome').controller('courseConllection', ['$scope', '$rootScope', 'StuRequestTrain', 'sysUserInfo', 'Msg', 'T', function ($scope,$rootScope, RS, sysUserInfo, Msg, T) {
    // 初始化参数
    $scope.params = {
        pageIndex: 1,  // 当前页面
        pageSize: 15, // 当前条数
        userid: sysUserInfo.getuserinfo().user_ID, //用户id
        orgid: sysUserInfo.getuserinfo().organization_ID//企业id
    };
    //用户token
    $scope.token = sysUserInfo.getuserinfotoken();
    // 课程收藏集合
    $scope.courseList = [];
    // 当前筛选总数
    $scope.courseCount = 0;
    // loading
    $scope.courseColnLoading = false;

    //打开课程
    $scope.openKe = function (item) {
        var url = $rootScope.upurl + '/dispatcher/redirect?url=' + encodeURI(encodeURI($rootScope.fileurl + "/resources/template/" + item.course_Id + ".html?arrangeId=" + item.course_Detailed + "&token=" + $scope.token));
        window.open(url);
    }
    // 查询下一页
    $scope.nextFindConllection = function () {
        if ($scope.courseColnLoading) {
            Msg.info("提示", "正在查询中...");
            return;
        }
        $scope.params.pageIndex += 1;
        $scope.findcollection();
    }
    // 查询列表
    $scope.findcollection = function () {
        if ($scope.courseColnLoading) {
            Msg.info("提示", "正在查询中...");
            return;
        }
        $scope.courseColnLoading = true;
        RS.courseCollection($scope.params).then(function (response) {
            $scope.courseColnLoading = false;
            if (response.errorcode == "0") {// 成功       
                angular.forEach(response.datas, function (data, index) {
                    $scope.courseList.push(data);
                });
                $scope.courseCount = response.numCount;
            } else {   // 获取失败 
                Msg.error("服务器异常！");
            }
        }, function errorCallback() {
            $scope.courseColnLoading = false;
            console.log("连接服务器失败！");
        });

    }
    $scope.findcollection();

} ]);

